$(function () {
    //上报统计
    getRecordData();
});

/**
 * 获取上报统计
 */
function getRecordData() {
    var url = ctx + "maindata";
    $.ajax({
        cache : true,
        type : "POST",
        url : url,
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            console.log('data',data);
            var days = data.days;
            var record_count_1 = data.record_count_1;
            var record_count_2 = data.record_count_2;
            var lineChart = echarts.init(document.getElementById("echarts-line-chart"));
            var lineoption = {
                title : {
                    text: '本月上报量统计'
                },
                tooltip : {
                    trigger: 'axis'
                },
                legend: {
                    data:['巡检正常','安全隐患']
                },
                grid:{
                    x:40,
                    x2:40,
                    y2:24
                },
                calculable : true,
                xAxis : [
                    {
                        type : 'category',
                        boundaryGap : false,
                        data : days //['周一','周二','周三','周四','周五','周六','周日']
                    }
                ],
                yAxis : [
                    {
                        type : 'value',
                        axisLabel : {
                            formatter: '{value}'
                        }
                    }
                ],
                series : [
                    {
                        name:'巡检正常',
                        type:'line',
                        data:record_count_1,
                    },
                    {
                        name:'安全隐患',
                        type:'line',
                        data:record_count_2,
                    }
                ]
            };
            lineChart.setOption(lineoption);
            $(window).resize(lineChart.resize);

            var months = data.months;
            var record_month_1 = data.record_month_1;
            var record_month_2 = data.record_month_2;

            var barChart = echarts.init(document.getElementById("echarts-bar-chart"));
            var baroption = {
                title : {
                    text: '全年的上报量统计'
                },
                tooltip : {
                    trigger: 'axis'
                },
                legend: {
                    data:['巡检正常','安全隐患']
                },
                grid:{
                    x:30,
                    x2:40,
                    y2:24
                },
                calculable : true,
                xAxis : [
                    {
                        type : 'category',
                        data : months
                    }
                ],
                yAxis : [
                    {
                        type : 'value'
                    }
                ],
                series : [
                    {
                        name:'巡检正常',
                        type:'bar',
                        data:record_month_1,
                    },
                    {
                        name:'安全隐患',
                        type:'bar',
                        data:record_month_2,
                    }
                ]
            };
            barChart.setOption(baroption);
            window.onresize = barChart.resize;
        }
    });
}
